package
{
	import mx.collections.ArrayCollection;
	import mx.core.Application;
	
	public class tMessageFormat
	{
		public var _contains_hyperlink:Boolean = false;
		public var _matches_keyword:Boolean = false;
		
		//public var _keywords:ArrayCollection = new ArrayCollection(["css", "flex", "jquery", "rt"]);  Application.application._keywords
		
		public function tMessageFormat()
		{
		}
		
		
		
		public function format_url_in_message(message:String):String
		{

			var urlPattern:RegExp = /(((http|ftp|https):\/\/){1}([a-zA-Z0-9_-]+)(\.[a-zA-Z0-9_-]+)+([\S,:\/\.\?=a-zA-Z0-9_-]+))/igs;
			
			if (urlPattern.test(message)==true)
			{
				//message = message.replace(urlPattern,"<a class=\"thyperlink\" target='_blank' href='event:$1'>$1</a>").toString();
				_contains_hyperlink = true;
			}				
			
			return message;
			
			
		}
            
		public function match_keywords(message:String):Boolean
		{
			//Alert.show("match_keywords - called"+Application.application.arr_keywords.length);
			if (Application.application.arr_keywords.length>0)
			{
				var i:int = 0;
				var a:ArrayCollection  = Application.application.arr_keywords;
				
				
				
				if (a.length>0)
				{
					var strPtn:String = "(?:"; //= "/";
					
					for each (var keyword:String in a)
					{
						
						{
							if (i>0)
							{
								strPtn += "|" + "\\b"+keyword+"\\b";
							}
							else
							{
								
								strPtn = "\\b"+keyword+"\\b";
							}
						}
						i++
					}
					
					//strPtn +="/i";
					//strPtn += ")b/";
					
					//Alert.show(strPtn);
					
					var pattern:RegExp = new RegExp(strPtn, "i");
					
					if (pattern.test(message)==true)
					{
						//Alert.show(message);
						return true;
						
					}
				}
			}
			return false;
			
		}
		
		public function format_date(_date:String):String
		{
			var local_date:Date = new Date(_date);
			_date = local_date.toString()
				
			var short_date:Array = _date.split(" ");
			
			var this_date:String = "";
			
			
			
			/*
			var local_date:Date = new Date(_date);
			var offsetMilliseconds:Number = local_date.getTimezoneOffset() * 60 * 1000;
			
			local_date.setTime(local_date.getDate() + offsetMilliseconds);
			
			
			
			return local_date.toString() ; //offsetMilliseconds.toString();*/

			
			//Alert.show(short_date.length.toString());
			
			if (short_date.length > 4)
			{
				for (var i:int=0; i<4; i++)
				{
					if (i>0)
					{
						this_date += " ";
					}
					this_date += short_date[i];
					
				}
				
				
				return this_date
				
			}
			else
			{
				return _date;
			}
			
		}
		
		

	}
	
}